﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Pixysoft.Framework.Noebe.Core
{
    class EntityPagingCommand : IEntityPagingCommand
    {
        IPagingCommand command = null;

        public EntityPagingCommand(IPagingCommand command)
        {
            this.command = command;
        }

        public string ColumnName
        {
            get
            {
                return command.ColumnName;
            }
            set
            {
                command.ColumnName = value;
            }
        }

        public int PageCapacity
        {
            get
            {
                return command.PageCapacity;
            }
            set
            {
                command.PageCapacity = value;
            }
        }

        public int PageIndex
        {
            get
            {
                return command.PageIndex;
            }
            set
            {
                command.PageIndex = value;
            }
        }

        public bool Reverse
        {
            get
            {
                return command.Reverse;
            }
            set
            {
                command.Reverse = value;
            }
        }

        public string Condition
        {
            get
            {
                return command.Condition;
            }
            set
            {
                command.Condition = value;
            }
        }

        public IPagingCommand PagingCommand
        {
            get
            {
                return command;
            }
        }

        public NoebeParameterCollection Parameters
        {
            get { return command.Parameters; }
        }

        public string GetSQL()
        {
            return command.GetSQL();
        }

        public List<T> ExecuteReader<T>()
        {
            command.TableName = EntityHelper.GetTableName(typeof(T));

            DataTable table = command.ExecuteReader();

            return EntityHelper.DataTableToEntity<T>(table);
        }
    }
}
